<template>
	<div class="container-bg">
		<div class="login-container flx-center" ref="flexContainer">
			<div class="login-box">
				<div class="login-logo">
					<img src="../../assets/images/client/login-logo.png" alt="" />
				</div>
				<div class="login-left">
					<img src="@/assets/images/client/login-left.png" alt="login" />
				</div>
				<div class="login-form">
					<div class="logo-text">欢迎登录合作机构端</div>
					<div class="logo-text">后台管理系统</div>
					<LoginForm />
					<div class="bottom-twoPage">
						<div>忘记密码</div>
						<div>注册</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script setup lang="ts" name="login">
import LoginForm from "./components/LoginForm.vue";
import { onMounted, ref } from "vue";
const flexContainer = ref<HTMLElement | null>(null);
onMounted(() => {
	// 初始化时为外层盒子加上缩放属性，防止刷新界面时就已经缩放
	if (flexContainer.value) {
		flexContainer.value.style.transform = `scale(${getScale()}) translate(-50%, -50%)`;
		flexContainer.value.style.width = `1920px`;
		flexContainer.value.style.height = `1080px`;
	}
	// 为浏览器绑定事件
	window.addEventListener("resize", resize);
});
/* 根据浏览器大小推断缩放比例 */
const getScale = (width = 1920, height = 1080) => {
	let ww = window.innerWidth / width;
	let wh = window.innerHeight / height;
	return ww < wh ? ww : wh;
};

/* 浏览器监听 resize 事件 */
const resize = () => {
	if (flexContainer.value) {
		flexContainer.value.style.transform = `scale(${getScale()}) translate(-50%, -50%)`;
	}
};
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
